﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

// 火球的技能逻辑
public class SkillLogicFireBall : SkillLogicBase
{
    protected override void initTimeLine()
    {
        _timeLine.AddEvent(0, 0, onSkillStart);
        _timeLine.AddEvent(0, 10, onAni); // 播动画
        // 放火球
        _timeLine.AddEvent(0.27192f, 1, onFlyObject);
        // 恢复到idle状态
        _timeLine.AddEvent(1.133f, 10, onAniEnd);
        // 音效
        _timeLine.AddEvent(1.133f, 0, onSkillEnd);
    }

    private void onFlyObject(int flyObjcetId)
    {
        var flyObjectData = FlyObjectTable.Instance[flyObjcetId];

        var fireBallObj = ResMgr.Instance.GetGameObject(flyObjectData.Path, _owner.transform.Find("Slot_Center").position);

        var flyObject = fireBallObj.AddComponent<FlyObject>();
        flyObject.Speed = flyObjectData.Speed;
        flyObject.Radius = flyObjectData.Radius;
        flyObject.Target = _curTarget;
        flyObject.OnHitTargetCallback = OnFlyObjectHitTarget;
    }

    // 当打击到目标时，回调
    private void OnFlyObjectHitTarget(FlyObject flyObject, Creature target)
    {
        // 掉血
        DamageMgr.Instance.PhysicsDamage(_owner, target, _skillObject);
        // 销毁
        ResMgr.Instance.Release(flyObject.gameObject);
    }

}
